<?php
namespace App\Models\Trade\Demand;

use App\Models\Model;

class DemandReportModel extends Model
{

    const TABLENAME = 'tw_trade_demand_report';

    /**
     * 获取一条数据
     *
     * @param int $userId            
     * @param int $demandId            
     * @return \Illuminate\Support\Collection
     */
    public static function findItem($userId, $demandId)
    {
        $where[] = ['user_id', $userId];
        $where[] = ['demand_id', $demandId];
        
        return self::dbTable()->where($where)->get();
    }

    /**
     * 添加一条数据
     *
     * @param int $userId            
     * @param int $demandId            
     * @return false | id
     */
    public static function addItem($userId, $demandId)
    {
        if (! $userId || ! $demandId) {
            return false;
        }
        $data['user_id'] = $userId;
        $data['demand_id'] = $demandId;
        $data['created'] = time();
        
        return self::dbTable()->insertGetId($data);
    }
}
